package com.itheima.springbootenable;

import com.itheima.springbootenableother.config.EnableUser;
import com.itheima.springbootenableother.config.MyImportBeanDefinitionRegistrar;
import com.itheima.springbootenableother.config.MyImportSelector;
import com.itheima.springbootenableother.config.UserConfig;
import com.itheima.springbootenableother.domain.Teacher;
import com.itheima.springbootenableother.domain.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;

import java.util.Map;


/*
* @Import的四种用法
* 1.导入Bean
* 2.导入配置类
* 3.导入ImportSelector的实现类
* 4.导入ImportBeanDefinitionRegistrar的实现类
* */


@SpringBootApplication
//@ComponentScan("com.itheima.springbootenableother.config")
//@Import(UserConfig.class)
//@EnableUser


//@Import(User.class)
//@Import(UserConfig.class)
//@Import(MyImportSelector.class)
@Import(MyImportBeanDefinitionRegistrar.class)
public class SpringbootEnableApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context =
                SpringApplication.run(SpringbootEnableApplication.class, args);

        //获取Bean
        /*Object user = context.getBean("user");
        System.out.println(user);*/

        //通过类型获取
        User user = context.getBean(User.class);
        System.out.println(user);

        /*Map<String, User> map = context.getBeansOfType(User.class);
        System.out.println(map);*/


        User user2 = (User) context.getBean("user");
        System.out.println(user2);

        Teacher teacher = context.getBean(Teacher.class);
        System.out.println(teacher);

    }

}
